<template>
  <div class="main">
    <a-input
      placeholder="input search text"
      size="large"
      class="search"
      v-model="username"
    />
    <br>
    <div class="sumbit" @click="toAdd()">添加为管理员</div>
  </div>
</template>

<script>
export default {
   data() {
    return {
      title: "标题",
      username: "",
      reg: /^([a-zA-Z]|[0-9])(\w|-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/,
    };
  },
  methods: {
    onSearch(value) {
      console.log(value);
    },
    toAdd(){
      if (this.username == "" || this.username == null) {
        this.$message.error("请输入管理员账号");
        return;
      }
        if (!this.reg.test(this.username)) {
        this.$message.error("账号必须是邮箱格式");
        return;
      }

      let param = {
        username: this.username,
      };

      this.$api.admin.addManager(param).then((res) => {
        console.log(res);
        if (res.code == 1) {
            this.$message.success("添加管理员成功～");

          // // console.log(res.code);
          // window.localStorage.clear();
          // // window.localStorage.setItem('userid',JSON.stringify(res.data.userInfo.id))
          // window.localStorage.token = res.data.token;
          // console.log("token=" + window.localStorage["token"]);
          // this.$router.push("/index");

          // this.$store.commit('setToken',JSON.stringify(res.data.token))
        }
        // this.data = res.data.data;
        // this.loading = false;
      });


    },
  },
};
</script>

<style scoped lang="scss">
.main {
  text-align: center;
}
.search {
  margin-top: 50px;
  width: 400px;
}

.sumbit {
  background: #1890ff;
  border-radius: 8px;
  height: 44px;
  color: whitesmoke;
  font-weight: 800;
  text-align: center;
  line-height: 44px;
  width: 400px;
  margin-top: 50px;
  font-size: 20px;
  display: inline-block;
}
</style>